home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / music / eked-m1.zoo / src / glob_ed.c < prev    next >
C/C++ Source or Header  |  1995-02-19  |  5KB  |  209 lines

  1. /*
  2.  *  EKED-M1 : Editor for Korg M1 synth; glob_ed.c : global editor
  3.  *  Copyright (C) 1995 Steven M. Eker (Steven.Eker@brunel.ac.uk)
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <stddef.h>
  21. #include <string.h>
  22. #include <gemfast.h>
  23. #include <aesbind.h>
  24. #include "gm/gem_man.h"
  25. #include "eked-m1.h"
  26. #include "defs.h"
  27. #include "types.h"
  28. #include "externs.h"
  29.  
  30. typedef struct {
  31.   int ob_number;
  32.   PARA_TYPE type;
  33. } GPARAMETER;
  34.  
  35. #define GT_SIZE        19
  36. static GPARAMETER glob_table[] =
  37. {
  38.   {G_TUNE,    SN50},
  39.   {G_TRANSPOSE,    SN12},
  40.   {G_DAMPER,    POL},
  41.   {G_PEDAL1,    PED},
  42.   {G_PEDAL2,    PED},
  43.   {G_SCALE,    SCAL},
  44.   {G_PURE,    KEY},
  45.   {G_USER + 1,    SN50},
  46.   {G_USER + 2,    SN50},
  47.   {G_USER + 3,    SN50},
  48.   {G_USER + 4,    SN50},
  49.   {G_USER + 5,    SN50},
  50.   {G_USER + 6,    SN50},
  51.   {G_USER + 7,    SN50},
  52.   {G_USER + 8,    SN50},
  53.   {G_USER + 9,    SN50},
  54.   {G_USER + 10,    SN50},
  55.   {G_USER + 11,    SN50},
  56.   {G_USER + 12,    SN50}
  57. };
  58.  
  59. static int in_use;
  60. static OBJECT *global;
  61. static BANK *edit_bank;
  62. static BYTE data[GLOBAL_SIZE];
  63. static int drum_handle[4];
  64.  
  65. static char *drum_title[] = {
  66.   "Drum Kit 1", "Drum Kit 2", "Drum Kit 3", "Drum Kit 4"
  67. };
  68.  
  69.  
  70. static void glob_setup();
  71. static void display(int x_pos, int y_pos, GRECT *clip, long usr_val);
  72. static int action(int handle, E_TYPE type, void *event,
  73.                   int x_pos, int y_pos, long usr_val);
  74.  
  75. void ge_window(BANK *bank)
  76. {
  77.   static char title[] = "Edit Bank 0 Global";
  78.   int t;
  79.  
  80.   if(in_use){
  81.     fm_alert(1, GLOB_ED_ALERT);
  82.     return;
  83.   }
  84.   rm_gaddr(R_TREE, GLOBAL, &global);
  85.   edit_bank = bank;
  86.   memcpy(data, bank->data, (size_t) GLOBAL_SIZE);
  87.   glob_setup();
  88.   title[10] = '0' + bank->bank_nr;
  89.   t = wm_open(NAME | CLOSER | FULLER | MOVER | SIZER |
  90.               UPARROW | DNARROW | VSLIDE |
  91.               LFARROW | RTARROW | HSLIDE,
  92.               (GRECT *) 0, title,
  93.               global[0].ob_width, global[0].ob_height,
  94.               char_w, char_h, &display, &action, 0L);
  95.   if(t < 0){
  96.     fm_alert(1, WINDOW_ALERT);
  97.     return;
  98.   }
  99.   in_use = TRUE;
  100.   bank->glob_win = t;
  101. }
  102.  
  103. static void glob_setup()
  104. {
  105.   int i;
  106.   
  107.   for(i = 0; i < GT_SIZE; i++)
  108.     para_fill(global + glob_table[i].ob_number, glob_table[i].type, data + i);
  109. }
  110.  
  111. static void display(int x_pos, int y_pos, GRECT *clip, long usr_val)
  112. {
  113.   global[0].ob_x = x_pos;
  114.   global[0].ob_y = y_pos;
  115.   objc_draw(global, 0, MAX_DEPTH, clip->g_x, clip->g_y, clip->g_w, clip->g_h);
  116. }
  117.  
  118. static int action(int handle, E_TYPE type, void *event,
  119.                   int x_pos, int y_pos, long usr_val)
  120. {
  121.   CLICK *c;
  122.   int i, ob;
  123.  
  124.   switch(type){
  125.   case E_CLEANUP:
  126.     for(i = 0; i < 4; i++){
  127.       if(drum_handle[i] != 0){
  128.         wm_closed(drum_handle[i]);
  129. /*
  130.  *    We must flush redraws generated by closing a drum window before
  131.  *    anything else gets closed otherwise they will become stale
  132.  *    and crash AES.
  133.  */
  134. /*    wm_flush(); */
  135.       }
  136.     }
  137.     edit_bank->glob_win = 0;
  138.     in_use = FALSE;
  139.     break;
  140.   case E_MESSAGE:
  141.     if(((int *) event)[0] == WM_CLOSED
  142.     && memcmp(data, edit_bank->data, (size_t) GLOBAL_SIZE) != 0){
  143.       switch(fm_alert(1, GLOB_QUIT_ALERT)){
  144.       case 1:    /* save */
  145.         memcpy(edit_bank->data, data, (size_t) GLOBAL_SIZE);
  146.         break;
  147.       case 3:    /* cancel */
  148.         return R_NOACT;
  149.       }
  150.     }
  151.     break;
  152.   case E_CLICK:
  153.     c = (CLICK *) event;
  154.     global[0].ob_x = x_pos;
  155.     global[0].ob_y = y_pos;
  156.     ob = objc_find(global, 0, MAX_DEPTH, c->m_x, c->m_y);
  157.     switch(ob){
  158.     case G_RESET:
  159.       if(wm_do_button(handle, global, ob, FALSE)){
  160.         memcpy(data, edit_bank->data, (size_t) GLOBAL_SIZE);
  161.         glob_setup();
  162.         wm_update(handle);
  163.         for(i = 0; i < 4; i++){
  164.           if(drum_handle[i] != 0)
  165.             wm_update(drum_handle[i]);
  166.         }
  167.       }
  168.       break;
  169.     case G_SAVE:
  170.       if(wm_do_button(handle, global, ob, FALSE))
  171.         memcpy(edit_bank->data, data, (size_t) GLOBAL_SIZE);
  172.       break;
  173.     case G_KIT1:
  174.     case G_KIT1 + 1:
  175.     case G_KIT1 + 2:
  176.     case G_KIT1 + 3:
  177.       if(wm_do_button(handle, global, ob, FALSE)){
  178.         i = ob - G_KIT1;
  179.         if(drum_handle[i] != 0)
  180.           wm_topped(drum_handle[i]);
  181.         else
  182.           drum_handle[i] = de_window(drum_title[i], data + 21 + 210 * i);
  183.       }
  184.       break;
  185.     default:
  186.       for(i = 0; i < GT_SIZE; i++){
  187.         if(glob_table[i].ob_number == ob){
  188.           para_edit(handle, global, ob, glob_table[i].type, -1, -1, data + i);
  189.           break;
  190.         }
  191.       }
  192.     }
  193.     break;
  194.   }
  195.   return R_NORMAL;
  196. }
  197.  
  198. void ge_drumexit(int handle)
  199. {
  200.   int i;
  201.  
  202.   for(i = 0; i < 4; i++){
  203.     if(drum_handle[i] == handle){
  204.       drum_handle[i] = 0;
  205.       break;
  206.     }
  207.   }
  208. }
  209.